<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<script>
$(function() {        
	$( "#tabs" ).tabs();
	$(".msg_write").click(function(){
		var url = $(this).attr("href");
		window.open(url,"쪽지 보내기","width=250,height=280,menubar=no,toolbar=no, menubar=no, resizable=no,");
		return false;
	});
	$("#find").click(function(){
		var nickName = $("#friendTxt").val();
		if(nickName==""){
			alert("닉네임을 입력하세요.");
			return;
		}
		$.ajax({
				type:"POST",
				url:"sns.do",
				data:"mode=findFriend&nick="+nickName,
				dataType:"json",
				success:function(jsonData){ // data 변수로 json 입력된다.
					var fvo = jsonData.fvo;
					var str ="";
					//alert(fvo);
					
					
					
					if(fvo!=null){
						//var nick = jsonData.fvo;   nick.nickName+    "+nick.uId+"
						var str = "";
						
						for(i=0;i<fvo.length;i++){
							str+="<img src='/img/profile/"+fvo[i].proImg+"'>"+"닉네임 : "+fvo[0].nickname+" info : "+fvo[i].info+" <a href='sns.do?mode=insert&uid=${sessionScope.mvo.uId }&fid="+fvo[0].uId+"'>친구 추가하기</a><br>";
						}
						
					}else{
						str="찾는 결과가 없습니다.";
					}					
					
					
					
					$("#result").html(str);
				}
			});
	});
});    
</script>
<c:choose>
	<c:when test="${requestScope.flag =='fail' }">
	
	<script>
	alert("친구 추가에 실패했습니다.");
	location.href="sns.do?mode=fmain&uid=${sessionScope.mvo.uId }";
	</script>	
	</c:when>	
	<c:otherwise>
	<div id="tabs">
    <ul>
            <li><a href="#tabs-1">친구목록</a></li>
            <li><a href="#tabs-2">신청목록</a></li>
            <li><a href="#tabs-3">받은목록</a></li>
            <li><a href="#tabs-4">친구검색</a></li>
    </ul>    
    <div id="tabs-1">
    	<h2>친구목록</h2>
    		<p>    			
					<c:forEach var="all" items="${requestScope.flist.allFriend }">
					<img src="/img/profile/${all.friend.proImg }">					
						${all.friend.nickname }
						${all.friend.info }
						<a href="member.do?mode=friendMain&uid=${all.friend.uId }">방문하기</a>
						<a href="sns/msgwrite.jsp?uid=${all.friend.uId }&nick=${all.friend.nickname}" class="msg_write">쪽지 보내기</a>
						<a href="sns.do?mode=delete&uid=${all.uId }&fid=${all.friend.uId }">친구 삭제</a>
						<br>					
					</c:forEach>				
    		</p>    
    </div> 
       
    <div id="tabs-2">        
    	<h2>신청목록</h2>        
    		<p>
				<c:forEach var="send" items="${requestScope.flist.sendReq }">	
						<img src="/img/profile/${send.friend.proImg }">				
						${send.friend.nickname }
						${send.friend.info }						
						<a href="sns.do?mode=delete&uid=${send.uId }&fid=${send.friend.uId }">취소 하기</a>
						<br>					
				</c:forEach>
    		</p>    
    </div>   
     
    <div id="tabs-3">        
    	<h2>받은목록</h2>        
    		<p>
				<c:forEach var="accept" items="${requestScope.flist.acceptReq }">
						<img src="/img/profile/${accept.friend.proImg }">
						${accept.friend.nickname }
						${accept.friend.info }
						<a href="sns.do?mode=accept&uid=${accept.uId }&fid=${accept.friend.uId }">수락하기</a>
						<a href="sns.do?mode=delete&uid=${accept.uId }&fid=${accept.friend.uId }">거절하기</a>
						<br>	
				</c:forEach>
    		</p>   
    </div>
    <div id="tabs-4">
    	<h2>친구 검색</h2>
    		<p>
    			<input type="text" id="friendTxt">
    			<input type="button" value="검색" id="find">
    			<div id="result"></div>
    		</p>   
    </div>
</div>
	</c:otherwise>
</c:choose>
<div id="msg_box">

</div>
